package jjn.round1;

/**
 * @author Jjn
 * @since 2023/5/1 22:14
 */
public class LeetCode714_BestTimeToBuyAndSellStockWithFee {
    public int maxProfit(int[] prices, int fee) {
        int[][] profit = new int[prices.length][2];
        profit[0][0] = 0;
        profit[0][1] = -prices[0];
        for (int i = 1; i < prices.length; i++) {
            // 已经持有股票,卖出去
            profit[i][0] = Math.max(profit[i - 1][0], profit[i - 1][1] + prices[i] - fee);
            profit[i][1] = Math.max(profit[i - 1][1], profit[i - 1][0] - prices[i]);
        }
        return profit[prices.length - 1][0];
    }
}
